package com.sam.im.sms.setting;

import android.content.Context;
import android.content.SharedPreferences;

import com.sam.im.sms.util.SPUtils;


/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/5/30.
 */
public class SMSSettingImpl implements Setting {
    private static Context sContext;
    private static String shareName = "SMS";
    private static SharedPreferences mPrefs;
    private static SharedPreferences.Editor editor;

    public SMSSettingImpl() {
    }

    public static void init(Context context) {
        sContext = context.getApplicationContext();
        mPrefs = sContext.getSharedPreferences(shareName, Context.MODE_PRIVATE);
        editor = mPrefs.edit();
    }

    public static Setting getInstance() {
        if (sContext == null) {
            throw new IllegalStateException("Setting is not initialized!");
        }
        return SingletonHelper.INSTANCE;
    }

    @Override
    public void setVerify(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    @Override
    public boolean isVerify(String key) {
        return mPrefs.getBoolean(key, false);
    }

    @Override
    public void setRemind(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    @Override
    public boolean isRemind(String key) {
        return mPrefs.getBoolean(key, false);
    }

    @Override
    public void setIntelligent(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    @Override
    public boolean isIntelligent(String key) {
        return mPrefs.getBoolean(key, false);
    }

    @Override
    public void setBlackList(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    @Override
    public boolean isBlackList(String key) {
        return mPrefs.getBoolean(key, false);
    }

    @Override
    public void setStranger(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    @Override
    public boolean isStranger(String key) {
        return mPrefs.getBoolean(key, false);
    }

    @Override
    public void setNumberKeyword(String key, String value) {
        editor.putString(key, value);
        editor.apply();
    }

    @Override
    public String getNumberKeyword(String key) {
        return mPrefs.getString(key, "");
    }

    @Override
    public void setWNumberKeyword(String key, String value) {
        editor.putString(key, value);
        editor.apply();
    }

    @Override
    public String getWNumberKeyword(String key) {
        return mPrefs.getString(key, "");
    }

    @Override
    public void remove(String key) {
        editor.remove(key);
        editor.commit();
    }

    private static class SingletonHelper {
        private final static SMSSettingImpl INSTANCE = new SMSSettingImpl();
    }
}
